<?php

$server = new soap_server;
$namespace = 'uri:auth';

$server->configureWSDL('AuthServer',$namespace,$location);
$server->wsdl->schemaTargetNamespace = $namespace;

$server->wsdl->addComplexType
(
    'AuthInfo',
    'complexType',
    'struct',
    'all',
    '',
    array
    (
        'login' => array('name'=>'login','type'=>'xsd:string'),
        'password' => array('name'=>'password','type'=>'xsd:string'),
    )
);

$server->register('auth',array('info' => 'tns:AuthInfo'),array('ret' => 'xsd:int'),$namespace,$namespace . '/auth','rpc','encoded');


function auth($info)
{
	global $bd;
	$login = $info['login'];
	$password = $info['password'];

	$sql = 'SELECT * FROM ' . TABLE_PREFIX . 'system_auth WHERE login="' . mysql_escape_string($login) . '" AND password = MD5("' . mysql_escape_string($password) . '")';
	$bd->QueryObj($sql);

	if (!$bd->data)
	{
		return new soap_fault('AUTH', '', 'Bad login or password!');
	}

	$_SESSION['login'] = $bd->data->login;
	$_SESSION['userid'] = $bd->data->id;
	
	return $bd->data->id;
	
}




if (substr_count($_SERVER['REQUEST_URI'],'wsdl')) //hack ... but it`s work
{
	header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
	die($server->wsdl->serialize(false));
}

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA); 
?>